package com.twoGroup.boot.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName
 * @Description TODO
 * @Author Xuyujie
 * @Date 2021/5/23 16:35
 * @Version 1.0
 **/
public class CommonUtils {




    /**
     * @Author Xuyujie
     * @Description //判断非空
     * @Date 16:39 2021/5/23
     * @Param [expression]
     * @return boolean
     **/
    public static boolean isNotnull(String expression){
        if(expression==null||expression.equals("")){
            return false;
        }else{
            return true;
        }
    }
    /**
     * @Author Xuyujie
     * @Description //根据传入的正则表达式进行判断
     * @Date 16:40 2021/5/23
     * @Param [param, expression]
     * @return boolean
     **/
    public static boolean ParamJudgeByRegular(String param, String expression){

        if(param.matches(expression)){
            return true;
        }else{
            return false;
        }
    }
    /**
     * @Author Xuyujie
     * @Description //判断数字是否在范围内
     * @Date 16:42 2021/5/23
     * @Param [num, min, max]
     * @return boolean
     **/
    public static boolean ParamIsInRange(String nums){
        if(nums==""){
            return false;
        }
        int num= Integer.parseInt(nums);
        if(num>=0&&num<= Integer.MAX_VALUE){
            return true;
        }else{
            return false;
        }
    }
    /**
     * @Author Xuyujie
     * @Description //判断传入的参数是否为数字
     * @Date 16:43 2021/5/23
     * @Param [str]
     * @return boolean
     **/
    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }
    /**
     * @Author Xuyujie
     * @Description //判断字符串的长度
     * @Date 16:44 2021/5/23
     * @Param [str, length]
     * @return boolean
     **/
    public static boolean judgeLength(String str, int length){
        if(str.length()>0&&str.length()<=10){
            return true;
        }else{
            return false;
        }
    }
    /**
     * @Author Xuyujie
     * @Description //判断字符串是否为汉字
     * @Date 17:17 2021/5/23
     * @Param [str]
     * @return boolean
     **/
    public static boolean isChineseStr(String str){
        Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
        char c[] = str.toCharArray();
        for(int i=0;i<c.length;i++){
            Matcher matcher = pattern.matcher(String.valueOf(c[i]));
            if(!matcher.matches()){
                return false;
            }
        }
        return true;
    }
}
